package com.zbec.mdrs.web;

import com.zbec.framework.core.entity.SystemDictionary;
import com.zbec.framework.core.entity.SystemDictionaryType;
import com.zbec.framework.core.service.SystemDictionaryService;
import com.zbec.framework.core.service.SystemDictionaryTypeService;
import com.zbec.mdrs.constants.Constants;
import com.zbec.mdrs.entity.report.ReportConfig;
import com.zbec.mdrs.service.ReportConfigService;
import com.zbec.mdrs.vo.ReportConfigVo;
import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by fxl on 2016/1/19.
 */

@Controller
@RequestMapping(value = "/reportConfig")
public class ReportConfigController {

    @Autowired
    private ReportConfigService reportConfigService;

    @Autowired
    private SystemDictionaryService systemDictionaryService;

    @Autowired
    private SystemDictionaryTypeService systemDictionaryTypeService;


    @RequestMapping(value = "/toReportConfig")
    public ModelAndView toReportConfig(HttpServletRequest request) {
        ModelAndView view=new ModelAndView("system/configReport");
        ReportConfig config=  reportConfigService.findReportConfig();
        SystemDictionaryType type=systemDictionaryTypeService.findCodeTypeByTypeCode(Constants.Constants_REPORT_TYPE);
        List<SystemDictionary> dictionaryList= systemDictionaryService.findCodeIterableByCodeType(type);

        SystemDictionaryType imp=systemDictionaryTypeService.findCodeTypeByTypeCode(Constants.Constants_IMPORT_TYPE);
        List<SystemDictionary> impList= systemDictionaryService.findCodeIterableByCodeType(imp);

        view.addObject("config",config);
        view.addObject("dictionaryList",dictionaryList);
        view.addObject("impList",impList);
        return view;
    }

    @RequestMapping(value = "/updateConfig")
    @ResponseBody
    public String updateConfig(ReportConfigVo vo){
        reportConfigService.updateReportConfigType(vo);
        JSONObject object=new JSONObject();
        object.put("result","true");
        return object.toJSONString();
    }



}
